<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">


<%@include file="/WEB-INF/include-head.jsp" %>

<script type="application/javascript">
    $(function () {
        initPagination();
    });

    function initPagination() {
        // 获取分页数据中的总记录数
        var totalRecord = ${requestScope['pageInfo'].total};

        // 声明 Pagination 设置属性的 JSON 对象
        let properties = {
            num_edge_entries: 3,   // 边缘页数
            num_display_entries: 5,   // 主体页数
            callback: pageSelectCallback,   // 用户点击“翻页”按钮之后 执行翻页操作的回调函数
            // 当前页，pageNum 从 1 开始，current_page是从0开始的，所以必须-1 后才可以赋值
            current_page: ${requestScope['pageInfo'].pageNum-1},
            prev_text: "上一页", next_text: "下一页",
            items_per_page: ${requestScope['pageInfo'].pageSize}   // 每页显示 1 项
        };

        // 调用分页导航条对应的 jQuery 对象的 pagination()方法生成导航条
        $("#Pagination").pagination(totalRecord, properties);
    }

    // 翻页过程中执行的回调函数
    // 点击“上一页”、“下一页”或“数字页码”都会触发翻页动作，从而导致当前函数被调用

    // pageIndex 是用户在页面上点击的页码数值
    function pageSelectCallback(pageIndex) {
        // pageIndex 是当前页页码的索引，相对于 pageNum 来说，pageIndex 比 pageNum 小 1
        let pageNum = pageIndex + 1;
        // 执行页面跳转也就是实现“翻页”
        window.location.href =
            "admin/get/page.html?pageNum=" + pageNum + "&keyword=" + ${empty param['keyword']?"-1":param['keyword']};
        // 取消当前超链接的默认行为
        return false;
    }

    // $(function () {
    //     $("#delete").click(function () {
    //         return confirm("你确定要删除 【" + $(this).parent().parent().find('td:eq(3)').text() + "】 吗？");
    //     });
    // });

</script>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <%@include file="/WEB-INF/include-nav.jsp" %>
</nav>
<div class="container-fluid">

    <%@include file="/WEB-INF/include-sidebar.jsp" %>

    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
            </div>
            <div class="panel-body">
                <form class="admin/get/page.html" role="form" style="float:left;" method="get">
                    <div class="form-group has-feedback">
                        <div class="input-group">
                            <div class="input-group-addon">查询条件</div>
                            <input class="form-control has-success" name="keyword" style="width:40%" type="text"
                                   placeholder="请输入查询条件">
                            <button type="submit" style="float:left;margin-left:10px;" class="btn btn-warning"><i
                                    class="glyphicon glyphicon-search"></i> 查询
                            </button>
                            <button type="button" class="btn btn-danger" style="float:right;margin-left:10px;">
                                <i class=" glyphicon glyphicon-remove"></i> 删除
                            </button>
                            <a href="admin/to/add.html" style="float:right;margin-left:10px;" class="btn btn-primary">
                                <i class="glyphicon glyphicon-plus"></i> 新增
                            </a>
                        </div>
                    </div>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${empty requestScope.pageInfo.list}">
                                <tr>
                                    <td colspan="6" style="text-align: center">抱歉！没有查到您要的数据</td>
                                </tr>
                            </c:if>
                            <c:if test="${!empty requestScope.pageInfo.list}">
                                <c:forEach items="${requestScope.pageInfo.list}" var="admin" varStatus="myStatus">
                                    <tr>
                                        <td>${myStatus.count}</td>
                                        <td><input type="checkbox"></td>
                                        <td>${admin.loginAcct}</td>
                                        <td>${admin.userName}</td>
                                        <td>${admin.email}</td>
                                        <td>
                                            <a href="assign/to/assign/role/page.html?adminId=${admin.id }&pageNum=${requestScope.pageInfo.pageNum }&keyword=${param.keyword }"
                                               class="btn btn-success btn-xs">
                                                <i class=" glyphicon glyphicon-check"></i>
                                            </a>

                                            <button type="button" class="btn btn-primary btn-xs">
                                                <a style="text-decoration:none;color:white"
                                                   href="admin/edit/${admin.loginAcct}/${admin.userName}/${admin.email}.html">
                                                    <i class=" glyphicon glyphicon-pencil"></i>
                                                </a>
                                            </button>
                                            <button type="button" id="delete" class="btn btn-danger btn-xs">
                                                <a style="text-decoration:none;color:white"
                                                   href="admin/remove/${admin.id}/${requestScope['pageInfo'].pageNum}/${param['keyword']}.html">
                                                    <i class=" glyphicon glyphicon-remove"></i>
                                                </a>
                                            </button>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" align="center">
                                    <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </form>
            </div>
<%--            <h1 style="text-align: center;color: red;">${empty requestScope['exception']?"":"您不允许访问该资源"}</h1>--%>
        </div>
    </div>

</body>
</html>